﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ImportMFGsFromFile.CApIMFFLogManager
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.IO;


namespace DnProcessSimulateCommands.ImportMFGsFromFile;

public class CApIMFFLogManager
{
  private StreamWriter writer;
  private bool isStreamOpened;
  private static CApIMFFLogManager loggerInstance = new CApIMFFLogManager();

  public string FilePath { get; set; }

  protected CApIMFFLogManager() => this.isStreamOpened = false;

  public static CApIMFFLogManager Logger => CApIMFFLogManager.loggerInstance;

  public void Init(string file)
  {
    this.FilePath = file;
    try
    {
      if (this.isStreamOpened)
        this.Close();
      this.writer = new StreamWriter(this.FilePath, false);
      this.writer.AutoFlush = true;
      this.isStreamOpened = true;
    }
    catch
    {
      this.isStreamOpened = false;
    }
  }

  public void LogNewLine()
  {
    if (!this.isStreamOpened)
      return;
    this.writer.WriteLine();
  }

  public void LogMessage(string message)
  {
    if (!this.isStreamOpened)
      return;
    this.writer.WriteLine(message);
  }

  public void LogCustom(string pre, string message)
  {
    if (!this.isStreamOpened)
      return;
    this.writer.WriteLine($"{pre} {message}");
  }

  public void Close()
  {
    if (!this.isStreamOpened)
      return;
    this.writer.Close();
    this.isStreamOpened = false;
  }
}
